package code
{
	import event.TriviaEvent;
	
	import flash.events.MouseEvent;
	
	import model.ApplicationModel;
	
	import mx.events.FlexEvent;
	
	import spark.components.BorderContainer;
	
	import view.StartTriviaView;
	
	import vo.Level;

	public class StartTriviaCB extends BorderContainer
	{
		
		private var _view : StartTriviaView;
		private var _aplication:Main; 
		[Bindable]
		public var _applicationModel : ApplicationModel = ApplicationModel.instance;
		
		public function StartTriviaCB()
		{
			super();
			this._view = this as StartTriviaView;
			_view.addEventListener(FlexEvent.CREATION_COMPLETE, doInit);
		}
		
		private function doInit(event:FlexEvent):void {
			_aplication = _view.parentApplication as Main;
			_view.btStartTrivia.addEventListener(MouseEvent.CLICK,startTrivia,false,0,false);
			(new TriviaEvent(TriviaEvent.TRIVIA_GET_USER).dispatch());
		}
		
		public function startTrivia (event:Event):void
		{
			_aplication.currentState = 	"stateQuestion";
			_applicationModel.level = (_view.cbLevel.selectedItem as Level).id;
			_aplication.panelExecuteQuestions.startQuestions();
		}
	}
}